﻿<%@ Page language="C#" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c"  %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<html>
<head id="Head1" runat="server">
	<meta http-equiv="X-UA-Compatible" content="IE=8"/>
	<meta name="GENERATOR" content="Microsoft SharePoint"/>
	<meta name="progid" content="SharePoint.WebPartPage.Document"/>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta http-equiv="Expires" content="0"/>
    <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">

	<title id="onetidTitle"></title>
	<SharePoint:CssLink runat="server" Version="4"/>
	<SharePoint:Theme runat="server"/>
	<SharePoint:ULSClientConfig runat="server"/>
	<script type="text/javascript">
	    var _fV4UI = true;
	</script>
	<SharePoint:ScriptLink language="javascript" name="core.js" OnDemand="true" runat="server" />
	<script type='text/javascript' src='jquery-1.8.2.min.js'></script>
	<SharePoint:CustomJSUrl runat="server" />
	<SharePoint:SoapDiscoveryLink runat="server" />

	<SharePoint:DelegateControl runat="server" ControlId="AdditionalPageHead" AllowMultipleControls="true"/>
	<SharePoint:SPShortcutIcon runat="server" IconUrl="/_layouts/images/favicon.ico" />
	<SharePoint:SPPageManager runat="server" />
	<SharePoint:SPHelpPageComponent Visible="false" runat="server" />
    <style>
        body.v4master {
	        overflow: auto;
	    }
    </style>
</head>
<body>
<body scroll="no" onload="if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();" class="v4master">
    <Sharepoint:SPSecurityTrimmedControl runat="server" Permissions="ManageWeb">
  <form id="Form1" runat="server" onsubmit="if (typeof(_spFormOnSubmitWrapper) != 'undefined') {return _spFormOnSubmitWrapper();} else {return true;}">
<script type="text/javascript">
    //load content of file
    $(function() {
		var url = (_spPageContextInfo.siteServerRelativeUrl == '/' ? '' : _spPageContextInfo.siteServerRelativeUrl) + "/wsp365/googleanalytics.js";
		$.get(url , function(data) {
			$('#txtTrackingCode').val(data);
		});            
	});

    function setupGoogleAnalytics() {
        //update javascript content
        $.ajax({
            type: "PUT",
	    async: false,
            url: (_spPageContextInfo.siteServerRelativeUrl == '/' ? '' : _spPageContextInfo.siteServerRelativeUrl) + "/wsp365/googleanalytics.js",
            enctype: 'multipart/form-data',
            data: $('#txtTrackingCode').val()
        });

        //update reference on public web
        //SP2013 this is not needed and client context is not defined...
        if (SP.ClientContext) {
            var script = "<script type='text/javascript' src='/wsp365/googleanalytics.js'><" + "/script>";
            var clientContext = new SP.ClientContext.get_current();
            var web = clientContext.get_site().get_rootWeb();
            this.properties = web.get_allProperties();
            this.properties.set_item('wh_fcproscript', script);
            web.update()
            clientContext.load(web);
            clientContext.load(this.properties);
            clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),
                               Function.createDelegate(this, this.onQueryFailed));
        }
        else {
            history.back();
        }
    }

    function onQuerySucceeded() {
        history.back();
    }

    function onQueryFailed(sender, args) {
        alert('Request failed. Ask on http://www.fiechter.eu/blog ' + args.get_message() + '\n' + args.get_stackTrace());
    }
</script>
  <div style="padding:5px;">
    <h1>Google Analytics Setup</h1>
    <p>Goto <a href="https://www.google.com/analytics" target="_blank">Google Analytics</a> and setup a profile for your website.
        Copy the tracking code from the google site and insert it in the textbox below.
    </p>
     <p>
     For example:<br />
     <code style="font-size:0.9em">
         <pre>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-26256938-1']);
_gaq.push(['_trackPageview']);

(function () {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
         </pre>
    </code>
     </p>
     <b>Please remove <code>&lt;script type="text/javascript"&gt;</code> and  <code>&lt;/script&gt;</code>:</b><br/>
     <textarea id="txtTrackingCode" rows="6" cols="50"></textarea>

      <br /><br />
     <div style="width:100%;" align="right">
        <input type="button" class="ms-ButtonHeightWidth" value="OK" onclick="setupGoogleAnalytics();" />
        &nbsp;
        <input type="button" class="ms-ButtonHeightWidth" value="Cancel" onclick="history.back();" />
        &nbsp;
    </div>

    <br /><br />
    <i>Provided to you by Adrian Fiechter / <a href="www.fiechter.eu/blog">www.fiechter.eu/blog</a></i>
</div>

</form>
        </Sharepoint:SPSecurityTrimmedControl>
</body>
</html>
